package com.atbun.cmsservice.service.impl;

import com.atbun.cmsservice.entity.CrmBanner;
import com.atbun.cmsservice.mapper.CrmBannerMapper;
import com.atbun.cmsservice.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-05-13
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    @Override
    public void pageBanner(Page<CrmBanner> pageParam, Object o) {
        QueryWrapper<CrmBanner> queryWrapper = new QueryWrapper<>();
        this.baseMapper.selectPage(pageParam,queryWrapper);
    }

    /**
     * 查询前两条banner
     * @return
     */
    @Override
    public List<CrmBanner> selectIndexList() {
//        根据id进行降序排列，显示排列之后前两调记录
        QueryWrapper<CrmBanner> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
//        last方法，拼接sql语句
        queryWrapper.last("limit 2");
        List<CrmBanner> crmBannerList = this.baseMapper.selectList(queryWrapper);
        return crmBannerList;
    }
}
